Skip to content

Feat/101/delete a department#107

Merged
Kimoo193 merged 3 commits into
mainfrom
feat/101/delete-a-department
Apr 7, 2025
Merged

Feat/101/delete a department#107
Kimoo193 merged 3 commits into
mainfrom
feat/101/delete-a-department

Conversation

@Kimoo193
Copy link
Copy Markdown
Contributor

@Kimoo193 Kimoo193 commented Apr 7, 2025

PR Checklist (required)

Please check if your PR fulfills the following requirements:

  • The commit message follows our guidelines.

  • Tests for the changes have been added (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation changes
  • Other... Please describe:

Related Issue

Closes #101

@Kimoo193 Kimoo193 added the feature For new feature label Apr 7, 2025
@Kimoo193 Kimoo193 requested a review from Copilot April 7, 2025 16:14
@Kimoo193 Kimoo193 self-assigned this Apr 7, 2025
@Kimoo193 Kimoo193 linked an issue Apr 7, 2025 that may be closed by this pull request
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (2)

src/routes/department.routes.js:50

  • [nitpick] Consider renaming the delete endpoint route to '/api/departments/:id' for consistency with other department routes.
router.delete(

src/controllers/department.controller.js:379

  • Ensure that the 'transaction' array is properly initialized prior to this check to prevent potential runtime errors if it is undefined.
if (transaction.length > 0) {

@Kimoo193
Copy link
Copy Markdown
Contributor Author

Kimoo193 commented Apr 7, 2025

This pull request includes several updates to the department.controller.js file and related files to improve error handling, add new functionality, and enhance code readability. The most significant changes include adding a soft delete feature for departments, improving error messages, and adding a new middleware for verifying owner or admin permissions.

New Feature:

  • Added a new softDeleteDepartment function to handle soft deletion of departments. This includes checking if the department exists and isn't already deleted, performing the deletion in a transaction, and returning appropriate success or error messages. ([src/controllers/department.controller.jsR424-R474](https://github.com/TaskTrial/server/pull/107/files#diff-b11fa539169ea6c7dbc536bdce30725583c2af43548b1a46e09c47b42e44f20cR424-R474))

Error Handling Improvements:

  • Enhanced error messages in the updateDepartment function by including a success field in the JSON responses for various error conditions, such as department not found, permission issues, and duplicate department names. ([[1]](https://github.com/TaskTrial/server/pull/107/files#diff-b11fa539169ea6c7dbc536bdce30725583c2af43548b1a46e09c47b42e44f20cL242-R290), [[2]](https://github.com/TaskTrial/server/pull/107/files#diff-b11fa539169ea6c7dbc536bdce30725583c2af43548b1a46e09c47b42e44f20cR308), [[3]](https://github.com/TaskTrial/server/pull/107/files#diff-b11fa539169ea6c7dbc536bdce30725583c2af43548b1a46e09c47b42e44f20cR344), [[4]](https://github.com/TaskTrial/server/pull/107/files#diff-b11fa539169ea6c7dbc536bdce30725583c2af43548b1a46e09c47b42e44f20cL333-R362), [[5]](https://github.com/TaskTrial/server/pull/107/files#diff-b11fa539169ea6c7dbc536bdce30725583c2af43548b1a46e09c47b42e44f20cL353-R386))

Code Quality Enhancements:

  • Updated the updateDepartment function to use optional chaining (?.) for checking the existence of addUsers and removeUsers arrays before processing them. ([[1]](https://github.com/TaskTrial/server/pull/107/files#diff-b11fa539169ea6c7dbc536bdce30725583c2af43548b1a46e09c47b42e44f20cL308-R332), [[2]](https://github.com/TaskTrial/server/pull/107/files#diff-b11fa539169ea6c7dbc536bdce30725583c2af43548b1a46e09c47b42e44f20cL333-R362))
  • Ensured that the transaction in updateDepartment is only executed if there are operations to perform, returning an error if no valid fields are provided for the update. ([src/controllers/department.controller.jsL353-R386](https://github.com/TaskTrial/server/pull/107/files#diff-b11fa539169ea6c7dbc536bdce30725583c2af43548b1a46e09c47b42e44f20cL353-R386))

Middleware Addition:

  • Added a new verifyOwnerOrAdmin middleware to restrict certain actions to only owners or admins, returning a 403 error if the user does not have the required role. ([src/middlewares/verifyOwnerOrAdmin.middleware.jsR1-R12](https://github.com/TaskTrial/server/pull/107/files#diff-5fe5d5ace5e7ce5ca6b6df7d95967fdc18d1a4bac1f1258d318265b9ab57cb58R1-R12))

Route Updates:

  • Updated department.routes.js to include the new softDeleteDepartment route and import the verifyOwnerOrAdmin middleware. ([[1]](https://github.com/TaskTrial/server/pull/107/files#diff-c35fbd24bf1a65e89dd968d2ee139ea0722980b2132ab8de9e2fed6cad061c00R6), [[2]](https://github.com/TaskTrial/server/pull/107/files#diff-c35fbd24bf1a65e89dd968d2ee139ea0722980b2132ab8de9e2fed6cad061c00R15), [[3]](https://github.com/TaskTrial/server/pull/107/files#diff-c35fbd24bf1a65e89dd968d2ee139ea0722980b2132ab8de9e2fed6cad061c00R49-R55))

@Kimoo193 Kimoo193 merged commit ffb1db7 into main Apr 7, 2025
11 checks passed
@Kimoo193 Kimoo193 deleted the feat/101/delete-a-department branch April 7, 2025 16:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature For new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Delete a department (*soft delete*)

2 participants